import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:qilo/core/constants/app_icons.dart';
import '../../../core/providers/global_state_coordinator.dart';
import '../../../core/widgets/transgression_reporting_portal.dart';

class OtherUserHeader extends StatelessWidget {
  final String userId;
  final VoidCallback onBackTap;

  const OtherUserHeader({
    super.key,
    required this.userId,
    required this.onBackTap,
  });

  @override
  Widget build(BuildContext context) {
    return Consumer<GlobalStateCoordinator>(
      builder: (context, coordinator, child) {
        final targetUser = coordinator.getDefaultUserById(userId);

        return Column(
          children: [
            SizedBox(
              width: double.infinity,
              child: Stack(
                children: [
                  SizedBox(
                    width: double.infinity,
                    height: (355.0 / 375.0) * MediaQuery.of(context).size.width,
                    child: Stack(
                      alignment: Alignment.center,
                      children: [
                        Image.asset("assets/images/my-top.png"),
                        Transform.translate(
                          offset: Offset(1.w, 25.h),
                          child: Container(
                            width: 90.w,
                            height: 90.w,
                            decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              color: targetUser == null ? Colors.white : null,
                              image:
                                  targetUser?.avatar.isNotEmpty == true
                                      ? DecorationImage(
                                        image: AssetImage(targetUser!.avatar),
                                        fit: BoxFit.cover,
                                      )
                                      : null,
                            ),
                            child:
                                targetUser == null
                                    ? Icon(
                                      MyIcons.iconPeople,
                                      size: 50.w,
                                      color: Colors.grey[600],
                                    )
                                    : null,
                          ),
                        ),
                      ],
                    ),
                  ),

                  // 返回按钮
                  Positioned(
                    top: MediaQuery.of(context).padding.top,
                    left: 16.w,
                    child: GestureDetector(
                      onTap: onBackTap,
                      child: Container(
                        width: 30.w,
                        height: 30.w,
                        decoration: BoxDecoration(shape: BoxShape.circle),
                        child: Icon(
                          Icons.arrow_back_ios_new,
                          color: Colors.white,
                          size: 24.w,
                        ),
                      ),
                    ),
                  ),

                  // 更多操作按钮
                  Positioned(
                    top: MediaQuery.of(context).padding.top,
                    right: 16.w,
                    child: GestureDetector(
                      onTap: () => _showMoreOptions(context),
                      child: Container(
                        width: 30.w,
                        height: 30.w,
                        decoration: BoxDecoration(shape: BoxShape.circle),
                        child: Icon(
                          MyIcons.iconReport,
                          color: Colors.white,
                          size: 24.w,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),

            // 用户名
            Text(
              targetUser?.userName ?? 'Unknown User',
              style: TextStyle(
                fontSize: 20.sp,
                fontFamily: 'Porter Sans Block',
                fontWeight: FontWeight.bold,
                color: Colors.white,
              ),
            ),
          ],
        );
      },
    );
  }

  /// 显示举报弹窗
  void _showMoreOptions(BuildContext context) {
    TransgressionReportingPortal.manifestReportingRealm(
      context,
      targetId: userId,
      targetType: 'user_profile',
      onReportSubmitted: (transgression) {
        // 举报成功后直接返回上一个页面
        Navigator.of(context).pop();
      },
    );
  }
}
